package cate.game.admin.menu.fight;

import cate.common.table.d.GDPlay;
import cate.common.table.hallow.row.HallowSkillRow;
import cate.game.GameBody;
import cate.game.admin.menu.MenuSetup;
import cate.game.fight.test.FightTestUtil;
import cate.game.role.Role;
import cate.game.role.res.formations.SingleFormation;
import cate.game.role.res.holy_pet.core.SingleHolyPetPO;
import cate.game.role.res.leader.hallows.Hallow;
import cate.game.role.res.racebadge.RaceBadge;
import cate.game.util.GameKit;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class FightMenu extends MenuSetup {



    public FightMenu(GameBody gameBody) {
        super("战斗");

        reg(gameBody, "强度测试", 2, "【参数1】场次数 【参数2】星级差 ",
                (role, params) -> {
                    final int fightNum = toInt(params, 0, 10000);
                    final int starDiff = toInt(params, 1, 2);
                    role.getGame().notice.message(role, "测试开始！");
                    for (int carryNum = 1; carryNum <= 3; carryNum++) {
                        Role robotRole = new Role(gameBody, GameKit.uid());
                        robotRole.newAllPart();
                        FightTestUtil.run(robotRole, fightNum, carryNum, starDiff);
                    }
                });

        reg(gameBody, "随机战斗", 1, "【参数1】：模拟次数",
                (role, params) -> {
                    int fightNum = toInt(params, 0, 10000);
                    if (fightNum <= 0) {
                        fightNum = 1;
                    }
                    role.getGame().notice.message(role, "模拟战斗开始！");
                    XSSFWorkbook workbook = new XSSFWorkbook();
                    FightTestUtil.buildSheet(workbook, "随机战斗", FightTestUtil.jobFight(role, fightNum).buildResult());
                    FightTestUtil.out(workbook, "随机战斗" + fightNum + "场");
                });

        reg(gameBody, "输出战斗详情", 0, "",
                (role, params) -> {
                    GDPlay.ENABLE_PLAY_DETAIL = true;
                    gameBody.notice.message(role, "已开启!");
                });

        reg(gameBody, "上阵灵宠", 0, "",
                (role, params) -> {
                    for (SingleHolyPetPO value : role.getRes().holyPet.pets.values()) {
                        value.setActive(true);
                        value.setFavorLevel(100);
                        value.setClosenessLevel(20);
                        value.setPracticeLevel(50);
                    }
                    for (int i = 1; i <= 3; i++) {
                        role.getRes().holyPet.positions.get(1).getPetPos().put(i, i);
                    }
                    role.getRes().holyPet.noticeUpdate();
                    gameBody.notice.message(role, "成功!");
                });


        reg(gameBody, "系统满战力", 0, "圣器、族徽、阵法",
                (role, params) -> {
                    for (Hallow item : role.getRes().leader.hallows.items) {
                        item.grade = 50;
                        item.times = 0;
                        HallowSkillRow skillRow = role.getGame().table.hallow.skill.getRowByTypeAndLevel(item.type, 26);
                        if (skillRow != null) {
                            item.skill.level = skillRow.level;
                            item.skill.chooseSkill = skillRow.skillId;
                        }
                        item.holySeal.level = 200;
                        item.refineSkill.level = 150;
                    }
                    for (RaceBadge raceBadge : role.getRes().raceBadge.list) {
                        raceBadge.level = 100;
                        raceBadge.grade = 10;
                    }
                    role.getRes().formations.level = 30;
                    for (int i = 1; i <= 4; i++) {
                        SingleFormation sf = new SingleFormation(i);
                        sf.initialize(role);
                        sf.active = true;
                        role.getRes().formations.formations.put(i, sf);
                    }
                    gameBody.notice.message(role, "成功!请重进游戏");
                });

//        reg(gameBody, "输出怪物战力", 0, "",
//                (role, params) -> {
////                    logger.info("======开始输出主线怪物战力======");
////                    for (AdventureCharpterRow row : role.getGame().table.adventure.charpter.getList()) {
////                        printPower(role, row.id, row.dynInsCode);
////                    }
////                    logger.info("======开始输出缚灵之塔怪物战力======");
////                    for (TowerMainRow row : role.getGame().table.tower.main.getList()) {
////                        printPower(role, row.id, row.dynInsCode);
////                    }
//                    logger.info("======开始输出食神记怪物战力======");
//                    for (BattleRoyaleLevelRow row : role.getGame().table.battleRoyale.level.getList()) {
//                        printPower(role, row.id, row.instanceConfig);
//                    }
//                    gameBody.notice.message(role, "成功!");
//                });
    }


//
//    private void printPower(Role role, int id, String config) {
//        EcResult<PlaySide> r = role.getGame().fight.side.createPlaySideByCode(config);
//        if (!r.ok()) {
//            System.out.println("关卡：" + id + "的怪物有问题");
//            return;
//        }
//        StringBuilder sb = new StringBuilder();
//        sb.append("关卡:").append(id);
//        sb.append(" 总战力:").append(r.data.getTotalPower()).append(" ");
//        for (BattleHero h : r.data.hs) {
//            sb.append(String.format("【英雄】%s", role.getGame().table.hero.base.get(h.hero.tid).foodNameNote));
//            //sb.append(" 【属性】：" + h.getAttr());
//            sb.append("【技能】");
//            h.getSkills().forEach(s -> sb.append(String.format("[%s]", role.getGame().table.skill.base.get(s).name)));
//        }
//       // logger.info(sb.toString());
//        System.out.println(sb);
//    }
}
